<?php

/**
 * faq actions.
 *
 * @package    sf_sandbox
 * @subpackage faq
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class faqActions extends autofaqActions
{

    /* public function preExecute()
    {
        $this->setLayout('design_sub');
    } */

	public function executeIndex()
	{
		$this->forward('faq', 'show');
	}
	
    protected function saveFaq($faq)
    {
            $faq->setCulture($this->getUser()->getCulture());
            $faq->setName($this->getRequestParameter('faq[name]'));
            $faq->setText($this->getRequestParameter('faq[text]'));
			$faq->save();
	}

  protected function updateFaqFromRequest()
  {
    $faq = $this->getRequestParameter('faq');
  }

  public function executeEdit()
  {
	$this->lng = $this->getRequestParameter('lng');
    $this->faq = $this->getFaqOrCreate();
	$this->faq->setCulture($this->getUser()->getCulture());

    if ($this->getRequest()->getMethod() == sfRequest::POST)
    {
      $this->updateFaqFromRequest();

      $this->saveFaq($this->faq);

      $this->setFlash('notice', 'Your modifications have been saved');

      if ($this->getRequestParameter('save_and_add'))
      {
        return $this->redirect('faq/create');
      }
      else if ($this->getRequestParameter('save_and_list'))
      {
        return $this->redirect('faq/list');
      }
      else
      {
        return $this->redirect('faq/edit?id='.$this->faq->getId());
      }
    }
    else
    {
      $this->labels = $this->getLabels();
    }
  }

	public function executeShow()
	{
		$this->faqs = FaqPeer::doSelect(new Criteria());
		$pager = new sfPropelPager('Faq', 4);
		$pager->setCriteria(new Criteria());
		$pager->setPage($this->getRequestParameter('page', 1));
		$pager->init();
		$this->pager = $pager;
	}
}
